﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog x-modal-dialog" style="width: 600px; margin-top: 100px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb no-bottom-border clearfix">

      <h2><i class="glyphicon glyphicon-search" title="过滤查询"></i>&nbsp;&nbsp;<span>渠道管理&nbsp;-&nbsp;过滤查询</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="GET" action="${ctx.host}/user-source" data-validate="true">

      <input type="hidden" name="filter" value="true" >
      <c:if test="${currentPrincipal.siteManager or currentPrincipal.siteServer}">
        <input type="hidden" name="site" value="${currentPrincipal.site.id}">
      </c:if>

      <div class="modal-body">
      
        <c:if test="${empty currentPrincipal.site}">
          <div class="form-group x-form-group">
            <label class="col-xs-4 control-label">门店</label>
            <div class="col-xs-6" style="width: 50%;">
              <select name="site" class="form-control select2">
                <option value="">全部门店</option>
                <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                  <option value="${site.id}">${site.name}</option>
                </c:forEach>
              </select>
            </div>
          </div>
        </c:if>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">渠道</label>
          <div class="pull-left col-xs-6" style="width: 50%;">
            <c:set value="${persist.listUserSourceTypeParent()}" var="typeParent"></c:set>
            <c:set value="${persist.listUserSourceTypeChildren()}" var="typeChildrenMap"></c:set>
            <select name="userSourceType" class="form-control" data-validate="required">

              <c:forEach var="typeParentItem" items="${typeParent}">
                <c:if test="${typeParentItem.name != '在营续课' && typeParentItem.name != '结营续课'}">
                <optgroup label="${typeParentItem.name}">
                  <c:choose>
                    <c:when test="${not empty typeChildrenMap[typeParentItem.id.toString()]}">
                      <c:forEach var="childrenTypes" items="${typeChildrenMap[typeParentItem.id.toString()]}">
                        <c:if test="${currentPrincipal.siteManager or currentPrincipal.siteServer}">
                          <c:choose>
                            <c:when test="${not empty childrenTypes.sites}">
                              <c:if test="${childrenTypes.sites.contains(currentPrincipal.site.code)}">
                                <option value="${childrenTypes.id}">${typeParentItem.name}-${childrenTypes.name}</option>
                              </c:if>
                            </c:when>
                            <c:otherwise>
                              <option value="${childrenTypes.id}">${typeParentItem.name}-${childrenTypes.name}</option>
                            </c:otherwise>
                          </c:choose>
                        </c:if>
                        <c:if test="${currentPrincipal.root or currentPrincipal.admin or currentPrincipal.areaServer or currentPrincipal.areaManager}">
                          <option value="${childrenTypes.id}">${typeParentItem.name}-${childrenTypes.name}</option>
                        </c:if>
                      </c:forEach>
                    </c:when>
                    <c:otherwise>
                      <option value="${typeParentItem.id}">${typeParentItem.name}</option>
                    </c:otherwise>
                  </c:choose>
                </optgroup>
                </c:if>
              </c:forEach>
            </select>
          </div>
        </div>

        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">学员名称</label>
          <div class="pull-left col-xs-6">
            <input type="text" class="form-control" name="name" value="${param.name}" placeholder="支持模糊查询"/>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">学员手机</label>
          <div class="pull-left col-xs-6">
            <input type="text" class="form-control" name="mobile" value="${param.mobile}" placeholder="请输入手机号码" data-validate="phone" />
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">首次时间</label>
          <div class="col-xs-6" style="width: 60%;">
            <div class="input-group">
              <input type="text" class="form-control date" name="occurStart" value="${param.occurStart}" placeholder="开始时间"/>
              <span class="input-group-addon"></span>
              <input type="text" class="form-control date" name="occurEnd" value="${param.occurEnd}" placeholder="结束时间"/>
            </div>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="control-label col-xs-4">是否到店：</label>
          <div class="pull-left col-xs-6">
            <input id="checkbox-admin" type="checkbox" data-on-color="success" data-off-color="warning" data-on-text="是" data-off-text="否" />
            <input id="input-admin" name="visited" type="hidden" class="form-control" value="${param.visited}" />
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="control-label col-xs-4">是否下单：</label>
          <div class="pull-left col-xs-6">
            <input id="checkbox-enterprise" type="checkbox" data-on-color="success" data-off-color="warning" data-on-text="是" data-off-text="否" />
            <input id="input-enterprise" name="ordered" type="hidden" class="form-control" value="${param.ordered}" />
          </div>
        </div>
        
      </div>

      <div class="modal-footer">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">查询</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>

    </form>
  </div>

</div>
  
  <script type="text/javascript">
  
  $(document).ready(function(){
	  
	  $('select[name="site"]').select2({
          placeholder : '请选择门店',
          minimumResultsForSearch : -1,
          allowClear : true,
        });
      
      $('select[name="group"]').select2({
            placeholder : '请选择分组',
            minimumResultsForSearch : -1,
            allowClear : true,
          });

      $('select[name="coach"]').select2({
          placeholder : '请选择教练',
          minimumResultsForSearch : 5,
          allowClear : true
      });
      
      $('#checkbox-enterprise').bootstrapSwitch({
          onSwitchChange: function(event, state) {
            $('#input-enterprise').val(state ? 'true' : 'false');
          }
        });
        
        $('#checkbox-admin').bootstrapSwitch({
           onSwitchChange: function(event, state) {
             $('#input-admin').val(state ? 'true' : 'false');
           }
         });
        
        $('.date').datetimepicker({
            format: 'yyyy-mm-dd',
            autoclose: true,
            language: 'zh-CN',
            todayBtn: 'linked',
            todayHighlight: true,
            pickerPosition: 'bottom-right',
            minView: 'month',
            startDate: '2017-05-01',
            endDate: '${today}'
          });
      
      var selectedStatus = $('select[name="coach"]').data('selected');
      $('select[name="coach"]').select2('val', selectedStatus);

  })
  
</script>
  
